package datastructure.tree;

import java.util.ArrayList;
import java.util.List;

/**
 * @author XY
 * @version 1.0
 * @date 2022/1/6 9:29
 * @Description  二叉树的中序遍历
 */
public class Leet94 {
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode() {}
        TreeNode(int val) { this.val = val; }
        TreeNode(int val, TreeNode left, TreeNode right) {
          this.val = val;
          this.left = left;
          this.right = right;
        }
    }

    class Solution {
        List<Integer> res = new ArrayList<>();
        public List<Integer> inorderTraversal(TreeNode root) {
            inorderTraversal1(root,res);
            return res;
        }

        public void inorderTraversal1(TreeNode root,List<Integer> list) {
            if(root ==null ){
                return ;
            }
            if(root.left!=null){
                inorderTraversal1(root.left,list);
            }
            res.add(root.val);
            if(root.right!=null){
                inorderTraversal1(root.right,list);
            }
        }
    }
}
